<?php

namespace app\admin\model\choi;

use think\Model;
use traits\model\SoftDelete;

class Banner extends Model
{

    use SoftDelete;

    

    // 表名
    protected $table = 'banner';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'onlineswitch_text',
        'typedata_text',
        'showdata_text',
    ];
    

    protected static function init()
    {
//        self::afterInsert(function ($row) {
//            $pk = $row->getPk();
//            $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
//        });
    }

    
    public function getOnlineswitchList()
    {
        return ['0' => __('Onlineswitch 0'), '1' => __('Onlineswitch 1')];
    }

    public function getTypedataList()
    {
        return ['index' => __('Typedata index'), 'brand' => __('Typedata brand'), 'about' => __('Typedata about'), 'social' => __('Typedata social'), 'news' => __('Typedata news'), 'contact' => __('Typedata contact'), 'duoyanshou' => __('Typedata duoyanshou'), 'qingshitu' => __('Typedata qingshitu')];
    }

    public function getShowdataList()
    {
        return ['zh-cn' => __('Showdata zh-cn'), 'yue' => __('Showdata yue'), 'en' => __('Showdata en')];
    }


    public function getOnlineswitchTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['onlineswitch']) ? $data['onlineswitch'] : '');
        $list = $this->getOnlineswitchList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getTypedataTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['typedata']) ? $data['typedata'] : '');
        $list = $this->getTypedataList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getShowdataTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['showdata']) ? $data['showdata'] : '');
        $list = $this->getShowdataList();
        return isset($list[$value]) ? $list[$value] : '';
    }




}
